package com.dujiu.config;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Slf4j
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = "config.jwt")
public class JwtConfig {
    private String secret; // 加密密钥
    private long tokenTime; //token有效时长
    private String header; // header名称

    @PostConstruct
    public void init() {
        log.info("加载JWT配置: " + this);
        log.info("JWT配置详情 - secret: " + secret +
                ", tokenTime: " + tokenTime +
                ", header: " + header);
        if (StringUtils.isEmpty(this.secret) || this.tokenTime <= 0L) {
            throw new IllegalStateException("JWT配置参数不合法: secret不能为空且tokenTime必须大于0");
        }
    }

    public JwtConfig() {
    }

    public JwtConfig(String secret, long tokenTime, String header) {
        this.secret = secret;
        this.tokenTime = tokenTime;
        this.header = header;
    }

}


















